#include "Dealer.h"

DealerEndpoint::DealerEndpoint(const std::string& address) {
    context = zmq::context_t();
    dealer = zmq::socket_t(context, zmq::socket_type::dealer);
    dealer.connect(address);
}

void DealerEndpoint::sendMessage(const std::string& message) {
    zmq::message_t msg(message.c_str(), message.size()); // 创建消息,c_str() 返回字符串的首地址
    dealer.send(msg, zmq::send_flags::none); // 发送消息
    std::cout << "Sent: " << message << std::endl;
}

void DealerEndpoint::receiveMessage() {
    zmq::message_t message;
    dealer.recv(message, zmq::recv_flags::none); // 接收消息
    std::cout << "Received: " << message.to_string() << std::endl;
}